﻿module core.hgescene;
private import core.hgeall;

class hgeSceneObj
{
	this(char[] scName){
		if(scName in scArray){	
			assert(0,"		err -> 场景类初始化出错: 和已有场景重名!		==	"~scName);
		}
		scArray[scName]=	this;	
		name= scName;
		mes("		* 创建场景 ==	",scName);
	}
static	void releaseAll(){
		mes("		*开始删除场景 --------	共	[ ",scArray.length, "	]	个");

		if(curr !is null) 	//先执行当前场景的离开函数 
			curr.leave();
		foreach( scName,sc; scArray)
		{
			mes("		* 删除场景 ==	",scName);
//			delete	scArray[scName];
			//scArray.remove(scName);
			delete sc;
			
		}
	}

	void entry(){   }
	void leave(){   }
	bool update(){	return true;    }
	bool draw()	{	return true;      }

	void To(char[] scName){
			if(scName == name)	return;
			if(scName in scArray)
			{
					next= scArray[scName];
			}
		}
			

static void setScene(hgeSceneObj _sc){
			curr= _sc;
		}
		
extern(C){
	static	bool updateAll(){
				return	curr.update;
			}
			
	static bool drawAll(){
			gameInfo.hge.Gfx_BeginScene();
				bool ret= curr.draw();
			gameInfo.hge.Gfx_EndScene();
			
				if(next){
					curr.leave();	//离开场景准备 
					curr=next;
					next=null;
					curr.entry();	//进入场景准备
				}
				return ret;
			}
}

protected:
	char[]	name;
	static	hgeSceneObj		curr, next;
	static hgeSceneObj[char[]] 	scArray;
private:
	
}
